package com.njupt.LinkTable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Author: wujiaming
 * @CreateTime: 2025/2/18 10:14
 * @Description: 234. 回文链表
 * @Version: 1.0
 */


public class IsPalindrome_234 {

    public boolean isPalindrome(ListNode head) {
        ListNode cur = head;
        List<Integer> list = new ArrayList<>();
        while(cur != null){
            list.add(cur.val);
            cur = cur.next;
        }
        cur = head;
        Collections.reverse(list);
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i) != cur.val){
                return false;
            }
            cur = cur.next;
        }
        return true;
    }

    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        ListNode node1 = new ListNode(2);
        ListNode node2 = new ListNode(2);
        ListNode node3 = new ListNode(1);
//        head.next = node1; node1.next = node2;node2.next = node3;

        IsPalindrome_234 test = new IsPalindrome_234();
        System.out.println(test.isPalindrome(head));

    }
}
